const puppeteer = require('puppeteer');
const url = "https://movie.douban.com/top250";
(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(url);
    //选取要点击的元素
    await page.click('.item')
    //页面等待1s
    await page.waitFor(1000)
    //page.evaluate()函数,可以让我们使用内置的DOM选择器
    const result = await page.evaluate(()=>{
        var $ = window.$;
        var items = $(".item");
        if(items.length>=1){
            var links=[];
            items.each((index,item)=>{
                var title = $(item).find(".info .title").eq(0).text();
                var imgUrl =$(item).find(".pic img").attr("src");
                links.push({
                    title,
                    imgUrl
                })
            })
        }
        return links;
    })
    browser.close();
    console.log(result)
})();